package com.example.day01

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.bumptech.glide.Glide

class testActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_test)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val btn = findViewById<TextView>(R.id.button2)
        btn.setOnClickListener {
            btn.text = "点击了按钮"

            Toast.makeText(this, "点击了按钮", Toast.LENGTH_LONG).show()
        }

        val btn2 = findViewById<TextView>(R.id.button3)
        btn2.setOnClickListener(this)

        val img = findViewById<ImageView>(R.id.img2)
        Glide.with(this)
            .load("https://tse3.mm.bing.net/th/id/OIP.K9Z4OgT3KU3XvbLVZytdVAHaJu?r=0&cb=thfc1&rs=1&pid=ImgDetMain&o=7&rm=3")
            .into(img)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.button3 -> Toast.makeText(this, "你好啊", Toast.LENGTH_SHORT).show()
        }
    }

    fun onBtnClick(view: View) {
        Toast.makeText(this, "点击了按钮", Toast.LENGTH_SHORT).show()
    }

}